package org.example.properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/properties")
@RestController
@SpringBootApplication
public class PropertiesController {

    private static  final Logger log = LoggerFactory.getLogger(PropertiesController.class);

    private final MyProperties1 myProperties1;

    private final MyProperties2 myProperties2;

    @Autowired
    public PropertiesController(MyProperties1 myProperties1, MyProperties2 myProperties2) {
        //通过 @Autowired的使用来消除 set ，get方法
        //这里注入 MyProperties1 MyProperties2
        this.myProperties1 = myProperties1;
        this.myProperties2 = myProperties2;
    }

    @GetMapping("/1")
    public MyProperties1 myProperties1(){
        //http://localhost:9090/demofa/properties/1
        log.info("===================================================");
        log.info(myProperties1.toString());
        log.info("===================================================");
        return  myProperties1;
    }

    @GetMapping("/2")
    public MyProperties2 myProperties2(){
        log.info("===================================================");
        log.info(myProperties2.toString());
        log.info("===================================================");
        return  myProperties2;
    }

    public static void main(String[] args) {
        SpringApplication.run(PropertiesController.class, args);
    }

}
